<? require_once("sitemap.php"); ?>
<html>
	<title><? echo (":" . $HTTP_SERVER_VARS['REMOTE_USER'] . ": ". $Botname); ?>'s EL-BOT Inventory Management - carried items</title>
<body>
	<h1><? echo ($Botname); ?>'s EL-BOT Inventory Management - carried items</h1>
	<form method="post" action="inventory.php"><input type="submit" name="submit" value="RELOAD"><input type="hidden" name="action" value="refresh"></form>
<?
		$result = mysql_query("SELECT inventory.id,knownitems.id,inventory.pos,knownitems.name,'',inventory.quantity FROM inventory,knownitems WHERE inventory.knownitemsid=knownitems.id AND inventory.botid='$botid' AND inventory.pos<36 ORDER BY knownitems.name",$db);
		echo (mysql_error());
	?>
    
	<h2>Legend:</h2>
	<table border="1" cellpadding="0" cellspacing="0">
	<tr>
			<td bgcolor="Yellow">items on sale</td>	
			<td bgcolor="Blue">items on purchase</td>
			<td bgcolor="Green">items on sale and purchase</td>
			<td bgcolor="Gray">items wearing - not available for trade</td>
			<td bgcolor="Red">Not on trade</td>
		</tr>
	</table>
	<h2>Bots Inventory:</h2>
        <table border="1" cellpadding="0" cellspacing="0">
                <tr bgcolor="Gray">
                        <td>id</td>
                        <td>name</td>
                        <td>quantity</td>
                        <td>description</td>
                </tr>
                <?
                  $buffer[]="1234567890";      
			while ($myrow = mysql_fetch_row($result)) {
			$passed=0;
			if(in_array($myrow[3],$buffer))
			{

			}
			else

			{
				//echo $buffer;
				$buffer[] = $myrow[3];
				if ($myrow[2]>35)
				{
					echo ('<tr bgcolor="Gray">');
					$passed=1;
				}
				else
				{
					$resultB = mysql_query("SELECT COUNT(*) FROM sellingitems,pricelist WHERE pricelist.knownitemsid='$myrow[1]' AND sellingitems.botid='$botid' AND sellingitems.pricelistid = pricelist.id",$db);
					echo (mysql_error());
			            $myrowB = mysql_fetch_row($resultB);		            

					$resultC= mysql_query("SELECT COUNT(*) FROM wanteditems,pricelist WHERE pricelist.knownitemsid='$myrow[1]' AND wanteditems.botid='$botid' AND wanteditems.pricelistid = pricelist.id",$db);
					echo (mysql_error());
					$myrowC = mysql_fetch_row($resultC);
					$sql = "SELECT COUNT(*) FROM inventory WHERE knownitemsid = '$myrow[1]' AND botid = '$botid'";
					$resultD = mysql_query($sql,$db);
					$myrowD = mysql_fetch_row($resultD);

					if ($myrowB[0]>0 && $myrowC[0]>0)
      	                  {
                              	echo ('<tr bgcolor="Green">');
                                    $passed=1;
                              }
					if ($passed==0)
					{
						if ($myrowB[0]>0)
						{
							echo ('<tr bgcolor="Yellow">');
							$passed=1;
						}					
						if ($myrowC[0]>0)
						{
							echo ('<tr bgcolor="Blue">');
							$passed=1;
						}
					}
				}

				if ($passed==0)
				{
					echo ('<tr bgcolor="Red">');
				}
			
            	    ?>
                        <td><?echo ($myrow[1])?></td>
                        <td><?echo ($myrow[3]); ?></td>
                        <td align='right'><? if ($myrowD[0]>1) echo "*S* "; echo ($myrow[5] * $myrowD[0]); ?></td>
                        <td><?echo ($myrow[4])?></td>
		</tr>
                <?
                        }
			}
                ?>
        </table>

	<?
		$result = mysql_query("SELECT COUNT(*) FROM inventory WHERE pos<36 and botid=$botid;",$db);
		$myrow = mysql_fetch_row($result);

		echo("Slots used: " . $myrow[0] . "/36 ( " . (36 - $myrow[0]) ." available)<br/>");
		
		$result = mysql_query("SELECT carrycapacitycur,carrycapacitybase FROM bots WHERE id='$botid'",$db);
                $myrow = mysql_fetch_row($result);
	
		echo("Weight: " . $myrow[0] . "/".$myrow[1]." ( " . ($myrow[1] - $myrow[0]) ." available)<br/>");
	?>
</body>
</html>
